import 'dart:async';

import 'package:flutter/material.dart';
import 'package:untitled2/pages/page/swiper.dart';

class pageBanner extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _PageBannerState();
  }
}

class _PageBannerState extends State<pageBanner> {
  List<String> list = [];
  late Timer timer;
  @override
  void initState() {
    super.initState();
    list.add("https://bpic.588ku.com/back_origin_min_pic/23/04/19/d8da78397b74c0fe3289694f6d57933e.jpg!/fh/350/quality/95/unsharp/true/compress/true");
    list.add("https://bpic.588ku.com/back_origin_min_pic/19/10/22/e108234a6bf3e56fc0253555f9c206d9.jpg!/fh/350/quality/95/unsharp/true/compress/true");
    list.add("https://bpic.588ku.com/back_origin_min_pic/23/04/18/0fcdd5ec660da8804c87bebaf7799316.jpg!/fh/350/quality/95/unsharp/true/compress/true");
    list.add("https://bpic.588ku.com/back_origin_min_pic/23/04/19/f5979c670618efe209c47cda0d513c53.jpg!/fh/350/quality/95/unsharp/true/compress/true");
    //定时器 每3秒执行一次
     timer = Timer.periodic(Duration(seconds: 3), (timer) {
      print(timer.tick);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("抖音无线滑动"),
      ),
      body: Swiper(list: list),
    );
  }

  @override
  void dispose() {
    timer.cancel();
    super.dispose();
  }
}

class MyContainer extends StatefulWidget {
  int num;

  MyContainer({super.key, required this.num});

  @override
  State<MyContainer> createState() => _MyContainerState();
}

class _MyContainerState extends State<MyContainer> with AutomaticKeepAliveClientMixin {
  @override
  Widget build(BuildContext context) {
    print("第${widget.num}页");
    return Container(
      color: Colors.red,
      child: Text("第${widget.num}页"),
    );
  }

  @override
  bool get wantKeepAlive => true; // 保持状态
}
